const { getConfig } = require('../config');
let { routePrefix } = getConfig();

let routes = {
    "/": {
        redirect: '$route/#/index'
    },
    "/index": {
        redirect: '$route/#/index'
    },
    "/list": {
        redirect: '$route/#/list'
    },
    "/form": {
        redirect: '$route/#/form'
    },
    "/404": {
        redirect: '$route/#/404'
    }
}

// 获取匹配的路由
module.exports.getRoute = function(ctx){
    let path = ctx.path;
    // 出现无法命中的，踢去 404
    let route  = routes[path] || routes['/404'];
    if(route) {
        if('string'==typeof route.redirect && route.redirect.includes('$route')){
            return route.redirect.replace('$route', routePrefix);
        }
    }
}